package com.testin.service.impl;

import java.util.List;

import com.testin.dao.UserTestingDao;
import com.testin.dao.impl.UserTestingDaoImpl;
import com.testin.model.Quest;
import com.testin.model.Require;
import com.testin.model.User;
import com.testin.service.UserTestingService;
import com.testin.utils.Result;


/**
 * 用户测试信息service
 * @author liuqianginfo
 *
 */
public class UserTestingServiceImpl  implements UserTestingService{
	private  UserTestingDao userTestingDao =new UserTestingDaoImpl();;
	/**
	 * 保存用户测试信息
	 * @param user
	 * @param require
	 * @param questList
	 * @return
	 */
	public Result saveUserTestingInfo(User user,Require require,List<Quest> questList) throws Exception{
		Integer requireId=null;
		int questNum=0;
		Result result=null;
		Integer userId=userTestingDao.saveUser(user);
		if(userId!=null){
			require.setUserId(userId);
			requireId=userTestingDao.saveRequire(require);
		}
		if(requireId!=null&&questList!=null&&questList.size()>0){
			for (int i = 0; i < questList.size(); i++) {
				questList.get(i).setTestId(requireId);
			}
			questNum=userTestingDao.saveQuest(questList);
			
		}
		result =new Result();
		if(requireId>0){
			result.setSuccess(true);
			result.setMessages("1");
		}else{
			result.setSuccess(false);
			result.setMessages("0");
		}
		
		return result;
		
	}


	public UserTestingDao getUserTestingDao() {
		return userTestingDao;
	}

	public void setUserTestingDao(UserTestingDao userTestingDao) {
		this.userTestingDao = userTestingDao;
	}
	
}
